#include<iostream>
#include<vector>
#include<queue>
#include<cstring>
#include<cmath>
#include<map>
#include<unordered_map>
#include<set>
#include<cstdio>
#include<algorithm>
#define debug(a) cout<<#a<<"="<<a<<endl;
using namespace std;
const int maxn=1e6+100;
typedef long long LL;
const LL mod=1e9+7;
inline LL read(){LL x=0,f=1;char ch=getchar();	while (!isdigit(ch)){if (ch=='-') f=-1;ch=getchar();}while (isdigit(ch)){x=x*10+ch-48;ch=getchar();}
return x*f;}
LL fac[maxn],inv[maxn],inv1[maxn];
LL a[maxn];
unordered_map<LL,LL>map1;
LL ksm(LL a,LL k){
    LL res=1;
    while(k>0){
        if(k&1) res=res*a%mod;
        k>>=1;
        a=a*a%mod;
    }
    return res%mod;
}
void init(){
    fac[0]=1;
    for(LL i=1;i<maxn-10;i++) fac[i]=fac[i-1]*i%mod;
    inv[0]=1;
    for(LL i=1;i<maxn-10;i++) inv[i]=inv[i-1]*ksm((LL)i,mod-2)%mod;
    inv1[0]=1;
    for(LL i=1;i<maxn-10;i++) inv1[i]=inv1[i-1]*ksm((LL)2,mod-2)%mod;
}
LL C(LL n,LL m){
   return (fac[m]%mod*inv[n]%mod*inv[m-n]%mod)%mod;
}
int main(void)
{
  init();
  LL n;n=read();
  LL cnt=0;
  for(LL i=1;i<=n;i++){
    a[i]=read();
    if(map1.count(a[i])){
        cnt++;
    }
    else map1[a[i]]=1;
  }
  LL ans=(fac[n]%mod*inv1[cnt]+mod)%mod;

  for(LL i=1;i<=cnt;i++){
      if(i&1){
         ans=(ans%mod-C(i,cnt)%mod*fac[n-i]%mod*inv1[cnt-i]%mod+mod)%mod;
      }
      else{
         ans=(ans%mod+C(i,cnt)%mod*fac[n-i]%mod*inv1[cnt-i]%mod+mod)%mod;
      }
      ans=(ans+mod)%mod;
  }
  printf("%lld\n",ans);
return 0;
}
